package p270jp.pxv.android.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import p014ae.View$OnClickListenerC0151s;
import p018ai.C0218e;
import p165fo.C3114c;
import p165fo.Subscribe;
import p270jp.pxv.android.R;
import p270jp.pxv.android.event.UpdateMuteButtonEvent;
import p270jp.pxv.android.legacy.model.PixivUser;
import p314lg.ButtonMuteBinding;
import p325m0.MutabilityOwnership;
import p347mm.MuteManager;

/* compiled from: MuteButton.kt */
/* renamed from: jp.pxv.android.view.MuteButton */
/* loaded from: classes2.dex */
public final class MuteButton extends LinearLayout {

    /* renamed from: i */
    public static final /* synthetic */ int f19563i;

    /* renamed from: a */
    public final ButtonMuteBinding f19564a;

    /* renamed from: b */
    public final Drawable f19565b;

    /* renamed from: c */
    public final Drawable f19566c;

    /* renamed from: d */
    public final int f19567d;

    /* renamed from: e */
    public final int f19568e;

    /* renamed from: f */
    public boolean f19569f;

    /* renamed from: g */
    public PixivUser f19570g;

    /* renamed from: h */
    public String f19571h;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public MuteButton(Context context, AttributeSet attributeSet) {
        super(context, attributeSet, 0, 2131887294);
        MutabilityOwnership.m3745m(context, "context");
        ViewDataBinding c = DataBindingUtil.m11370c(LayoutInflater.from(context), R.layout.button_mute, this, true);
        MutabilityOwnership.m3746l(c, "inflate(LayoutInflater.f….button_mute, this, true)");
        ButtonMuteBinding q2Var = (ButtonMuteBinding) c;
        this.f19564a = q2Var;
        TypedArray obtainStyledAttributes = context.getTheme().obtainStyledAttributes(attributeSet, C0218e.f747e, 0, 2131887294);
        Drawable drawable = obtainStyledAttributes.getDrawable(0);
        if (drawable != null) {
            this.f19565b = drawable;
            Drawable drawable2 = obtainStyledAttributes.getDrawable(2);
            if (drawable2 != null) {
                this.f19566c = drawable2;
                this.f19567d = obtainStyledAttributes.getColor(1, 0);
                this.f19568e = obtainStyledAttributes.getColor(3, 0);
                obtainStyledAttributes.recycle();
                q2Var.f22131q.setOnClickListener(new View$OnClickListenerC0151s(this, 22));
                return;
            }
            throw new IllegalArgumentException("Required value was null.".toString());
        }
        throw new IllegalArgumentException("Required value was null.".toString());
    }

    @Override // android.view.View, android.view.ViewGroup
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        C3114c.m6284b().m6276j(this);
    }

    @Override // android.view.View, android.view.ViewGroup
    public void onDetachedFromWindow() {
        C3114c.m6284b().m6274l(this);
        super.onDetachedFromWindow();
    }

    @Subscribe
    public final void onEvent(UpdateMuteButtonEvent updateMuteButtonEvent) {
        PixivUser pixivUser;
        MutabilityOwnership.m3745m(updateMuteButtonEvent, "event");
        PixivUser user = updateMuteButtonEvent.getUser();
        if (!(user == null || (pixivUser = this.f19570g) == null)) {
            long j = user.f19078id;
            MutabilityOwnership.m3747j(pixivUser);
            if (j == pixivUser.f19078id) {
                setMuted(updateMuteButtonEvent.getIsMuted());
                return;
            }
        }
        if (this.f19571h != null && updateMuteButtonEvent.getTagName() != null && MutabilityOwnership.m3749h(updateMuteButtonEvent.getTagName(), this.f19571h)) {
            setMuted(updateMuteButtonEvent.getIsMuted());
        }
    }

    public final void setMuted(boolean z) {
        String str;
        this.f19569f = z;
        Drawable drawable = z ? this.f19565b : this.f19566c;
        int i = z ? this.f19567d : this.f19568e;
        this.f19564a.f22131q.setBackground(drawable);
        this.f19564a.f22132r.setTextColor(i);
        TextView textView = this.f19564a.f22132r;
        if (this.f19569f) {
            str = getResources().getString(R.string.unmute);
        } else {
            str = getResources().getString(R.string.mute);
        }
        textView.setText(str);
    }

    public final void setTagName(String str) {
        MutabilityOwnership.m3745m(str, "tagName");
        this.f19571h = str;
        this.f19569f = MuteManager.f23061h.f23064c.containsKey(str);
    }

    public final void setUser(PixivUser pixivUser) {
        MutabilityOwnership.m3745m(pixivUser, "user");
        this.f19570g = pixivUser;
        this.f19569f = MuteManager.f23061h.m3540c(pixivUser.f19078id);
    }
}
